find: match nothing when -mindepth exceeds -maxdepth - #854
Open
Developer1010x wants to merge 1 commit into
Open
Conversation
walkdir's min_depth()/max_depth() setters clamp min_depth down to max_depth, so an impossible range such as `-mindepth 3 -maxdepth 1` silently became `-mindepth 1 -maxdepth 1` and printed entries at depth 1. GNU find matches nothing for such a range. Detect the impossible range up front, walk the starting point only so errors for it are still reported, and discard every entry the walk yields. Fixes uutils#778
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #854 +/- ##
==========================================
+ Coverage 92.31% 92.32% +0.01%
==========================================
Files 35 35
Lines 7466 7482 +16
Branches 388 391 +3
==========================================
+ Hits 6892 6908 +16
Misses 433 433
Partials 141 141 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #778.
Problem
An empty depth range should match nothing, but uutils printed entries at depth 1.
Cause
walkdir'smin_depth()andmax_depth()setters both clampmin_depthdown tomax_depth, so-mindepth 3 -maxdepth 1was silently turned into-mindepth 1 -maxdepth 1. Swapping the call order does not help — either setter clamps.Fix
Detect the impossible range before building the walker. In that case walk the starting point only (
max_depth(0)), so errors for a bad starting point are still reported, and discard every entry the walk yields.Verification
Every combination below now agrees with GNU find on output and exit code, with and without
-depth:-mindepth 3 -maxdepth 1-mindepth 5 -maxdepth 0-mindepth 1 -maxdepth 3-mindepth 2 -maxdepth 2-maxdepth 1-mindepth 2Added
find_mindepth_greater_than_maxdepth, covering both traversal orders.cargo test,cargo clippy --all-targets -- -D warningsandcargo fmt --checkare all clean.No GNU source was consulted; the fix is derived from
walkdir's documented clamping behaviour.